import vnode from "./vnode.js"

export  default function(sel,data,c){
    if(arguments.length !== 3){
        throw new Error('必须是3个参数')
    }
    //检查参数c的类型
    if(typeof c === "string" || typeof c === "number"){
        return vnode(sel,data,undefined,c,undefined);
    }else if(Array.isArray(c)){
        let children = []
        for(let i=0;i<c.length;i++){
            if(!(typeof c[i] === "object" && c[i].hasOwnProperty('sel'))){
                  throw new Error('传入的数组参数有项不是h函数')
            }
            children.push(c[i])
        }
        return vnode(sel,data,children,undefined,undefined);
    }else if(typeof c === "object" && c.hasOwnProperty('sel')){
        let children = [c];
        return vnode(sel,data,children,undefined,undefined);
    } else{
        throw new Error('传入的第三个参数类型不对')
    }
}